#coding=utf-8
import arcpy
path = r'D:\WorkData\20250712四川河流\0903处理'
arcpy.env.workspace = path
arcpy.env.overwriteOutput = True
spatial_ref = arcpy.SpatialReference(4326)

rivs1 = r'D:\WorkData\20250712四川河流\0903处理\rivs_ok.shp'.decode('utf-8')
xzq = r'D:\WorkData\20250712四川河流\0903处理\XZQ_SC_CITY.shp'.decode('utf-8')
cs1 = arcpy.da.UpdateCursor(rivs1, ['SHAPE@','name','city'])
i = 1
for row1 in cs1:
    print i, row1[1]
    cs2 = arcpy.da.SearchCursor(xzq,['SHAPE@','name'])
    cityList = []
    for row2 in cs2:
        if row2[0].contains(row1[0]) or row2[0].crosses(row1[0]):
            if(row2[1] not in cityList):
                cityList.append(row2[1])
    cs2.reset()
    row1[2] = ','.decode('utf-8').join(cityList)
    cs1.updateRow(row1)

    i+=1
